let fetch = require("../../utils/fetch");
let mta = require('../../utils/mta_analysis.js');
let app = getApp();
Page({
	data: {
		num: '85',
		shopList: [],
		urlAddress: getApp().globalData.imageUrl,
		urlAddress1: getApp().globalData.imageUrl

	},

	onLoad: function(options) {

	},

	onReady: function() {
		console.log('onReady')
	},
	onShow: function() {
		// if (getApp().globalData.common.reserveShopName&&wx.getStorageSync('furn')) {
		// 	wx.setStorageSync('furn',false);
		// 	wx.switchTab({
		//      url: '/pages/reserve/reserve'
		//     })
		// 	return
		// }
		this.getShops()
	},
	onHide: function() {},
	onUnload: function() {

	},
	getShops: function() {
		wx.showLoading({
			title: '加载中',
			mask: true
		});
		var _self = this;
		console.log("memId------"+getApp().globalData.userInfo.memId);
		wx.getLocation({
			type: 'gcj02',
			success: function(res) {
				console.log("获取经纬度");
				var latitude = res.latitude
				var longitude = res.longitude
				var speed = res.speed
				var accuracy = res.accuracy
				wx.request({
					url: getApp().globalData.baseUrl + '/applet/reserve/shopsOfSaleOut.do',
					data: {
						x: longitude,
						y: latitude
						// memId:getApp().globalData.userInfo.memId

					},
					header: getApp().globalData.header,
					success: function(res) {
						console.log("获取门店信息");
						console.log(res.data.obj);
						wx.hideLoading();
						_self.setData({
							shopList: res.data.obj

						})


					}
				})
			},
			fail: function() {
				wx.hideLoading();
				console.log("失败")
				wx.request({
					url: getApp().globalData.baseUrl + '/applet/reserve/shopsOfSaleOut.do',
					header: getApp().globalData.header,
					success: function(res) {
						wx.hideLoading();
						_self.setData({
							shopList: res.data.obj

						})


					}
				})
			}
		})

	},
	onShareAppMessage: function (ops) {
		if (ops.from === 'button') {
			// 来自页面内转发按钮
			console.log(ops.target)
		}
		return {
			title: '小麦铺',
			path: 'pages/loading/loading', // 路径，传递参数到指定页面。
			imageUrl: '../../image/yu_e.png', // 分享的封面图
			success: function (res) {
				// 转发成功
				console.log("转发成功:" + JSON.stringify(res));
			},
			fail: function (res) {
				// 转发失败
				console.log("转发失败:" + JSON.stringify(res));
			}
		}
	},
	chooseAction: function(e) {
	   
		// if (e.currentTarget.dataset.type != 1) {
		// 	wx.showToast({
		// 		title: '门店已歇业',
		// 		icon: 'none',
		// 		duration: 1000,
		// 		mask: true,
		// 		'success': function() {

		// 		}
		// 	})
		// 	return;
		// }
		getApp().globalData.common.reservebAdd = null;
		getApp().globalData.common.reservesAdd = null;
		getApp().globalData.common.reserveVid = null;
		getApp().globalData.common.reservesNote = null;
		getApp().globalData.common.reserveSelfAdd = null;
		getApp().globalData.common.categoryCode = null;
		 console.log('e.currentTarget.dataset.name')
	    console.log(e.currentTarget.dataset.name)
	   getApp().globalData.common.reserveShopCode = e.currentTarget.dataset.code;
	   getApp().globalData.common.reserveShopName = e.currentTarget.dataset.name;
		wx.switchTab({
		  url: '/pages/reserve/reserve'
		})

	}
})